Skip to content

feat(sanity): add --fix option#258

Merged
ktro2828 merged 6 commits into
mainfrom
feat/sanity/fix-option
Jan 30, 2026
Merged

feat(sanity): add --fix option#258
ktro2828 merged 6 commits into
mainfrom
feat/sanity/fix-option

Conversation

@ktro2828

@ktro2828 ktro2828 commented Jan 29, 2026

Copy link
Copy Markdown
Collaborator

What

This pull request introduces a new --fix option to the t4sanity CLI tool, enabling automatic fixing of issues detected by sanity checks. It updates the CLI, core checker logic, reporting, and documentation to support and clearly present this new feature. Additionally, it improves the exclusion and reporting of checks.

The following diagram shows the logic of checkers:

flowchart LR
    Start --> A{Can skip?}
    A --> |Yes| B[Skip check and <br/>returns skipped report]
    A --> |No| C[Perform check]
    C --> D{Failed and --fix=True?}
    D --> |Yes| E[Fix issues]
    E --> F[Return report]
    D --> |No| F
Loading

Major new feature: Automatic fixing of issues

  • Adds a --fix option to the CLI, allowing users to attempt to automatically fix issues found during sanity checks. [1] [2] [3]
  • Updates the Checker interface and all checker calls to support a fix parameter, and adds a fix() method for implementing fix logic in each checker. [1] [2]
  • Modifies the reporting system to track and display which issues were fixed, updating the Report dataclass and summary output to include a "Fixed" column. [1] [2] [3] [4] [5]

Documentation improvements

  • Updates the CLI documentation to describe the new --fix option and provide usage examples.
  • Improves the documentation of the --exclude option with clearer examples for excluding rules or groups.

Tests

I checked this feature with sample data tests/sample/t4dataset by editting category.json.

Before running t4sanity tests/sample/t4dataset --fix:

[
  {
    "token": "1c22a023c1a214447d0bc497088c9a3d",
    "name": "car",
    "description": "Vehicle designed primarily for passenger transportation",
    "index": null
  },
  {
    "token": "4db2cce0862dbdf1385186fd604d477a",
    "name": "pedestrian",
    "description": "Person walking or standing",
    "index": 1
  },
  {
    "token": "0531921ca79d7ca8c3815a77122de529",
    "name": "bicycle",
    "description": "Two-wheeled vehicle propelled by pedaling",
    "index": 2
  },
  {
    "token": "bdb3ce20fb731507f2ecf9387071335f",
    "name": "traffic_cone",
    "description": "Cone-shaped marker used to redirect traffic",
    "index": 3
  }
]

After running:

[
  {
    "token": "1c22a023c1a214447d0bc497088c9a3d",
    "name": "car",
    "description": "Vehicle designed primarily for passenger transportation",
    "index": 0
  },
  {
    "token": "4db2cce0862dbdf1385186fd604d477a",
    "name": "pedestrian",
    "description": "Person walking or standing",
    "index": 1
  },
  {
    "token": "0531921ca79d7ca8c3815a77122de529",
    "name": "bicycle",
    "description": "Two-wheeled vehicle propelled by pedaling",
    "index": 2
  },
  {
    "token": "bdb3ce20fb731507f2ecf9387071335f",
    "name": "traffic_cone",
    "description": "Cone-shaped marker used to redirect traffic",
    "index": 3
  }
]

The dumped report would be like:

[
    {
            "id": "REC007",
            "name": "category-indices-consistent",
            "severity": "ERROR",
            "description": "All categories must either have a unique 'index' or all have a 'null' index.",
            "status": "FAILED",
            "reasons": [
                "All categories either must have an 'index' set or all have a 'null' index."
            ],
            "fixed": true
        }
]

@github-actions github-actions Bot added documentation Improvements or additions to documentation new-feature New feature or request labels Jan 29, 2026
@github-actions

github-actions Bot commented Jan 29, 2026

Copy link
Copy Markdown
Contributor

☂️ Python Coverage

current status: ❌

Overall Coverage

Lines Covered Coverage Threshold Status
4192 3455 82% 50% 🟢

New Files

No new covered files...

Modified Files

File Coverage Status
t4_devkit/sanity/checker.py 91% 🟢
t4_devkit/sanity/context.py 83% 🟢
t4_devkit/sanity/record/rec007.py 66% 🔴
t4_devkit/sanity/result.py 63% 🔴
t4_devkit/sanity/run.py 100% 🟢
TOTAL 81% 🔴

updated for commit: 8c77fb5 by action🐍

@ktro2828 ktro2828 force-pushed the feat/sanity/fix-option branch 2 times, most recently from 83593cc to ca5df65 Compare January 29, 2026 15:18
@ktro2828 ktro2828 self-assigned this Jan 29, 2026
@ktro2828 ktro2828 force-pushed the feat/sanity/fix-option branch 2 times, most recently from 2c9efa0 to 3f28a79 Compare January 30, 2026 00:14
Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
@ktro2828 ktro2828 force-pushed the feat/sanity/fix-option branch from 3f28a79 to 1d633a7 Compare January 30, 2026 00:22
@ktro2828 ktro2828 marked this pull request as ready for review January 30, 2026 00:46
Comment thread t4_devkit/sanity/checker.py
Comment thread t4_devkit/sanity/result.py Outdated
Comment thread t4_devkit/sanity/result.py Outdated
@mojomex

mojomex commented Jan 30, 2026

Copy link
Copy Markdown
Contributor

Tested with a few corrupted category.jsons and it behaved correctly with and without --fix.

@SamratThapa120 SamratThapa120 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks.

@shekharhimanshu shekharhimanshu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 💯
Thank you

Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
@ktro2828 ktro2828 merged commit c51d395 into main Jan 30, 2026
4 of 5 checks passed
@ktro2828 ktro2828 deleted the feat/sanity/fix-option branch January 30, 2026 04:16
ktro2828 added a commit that referenced this pull request Jan 30, 2026
* feat: add --fix option

Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>

* feat: override fix method for REC007

Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>

* refactor: do refactoring

Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>

* docs: update document

Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>

* docs: add docstring of the behavior

Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>

* refactor: update report color

Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>

---------

Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation new-feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants